package jp.tkym.labs.m3d;

import java.util.HashMap;
import java.util.Map;

import jp.tkym.labs.geom.CoordinateModel;

abstract class AbstractModelingPoint3D{
	protected CoordinateModel coordinateModel;
	protected Map<String, ModelingPoint3D> pointMap = new HashMap<String, ModelingPoint3D>();
	protected AbstractModelingPoint3D parent = null;
	
	AbstractModelingPoint3D(String name){
		coordinateModel = new CoordinateModel(name);
	}
	
	public ModelingPoint3D on(String name){
		ModelingPoint3D model = pointMap.get(name);
		if(model == null){
			model = create(name, this.coordinateModel);
			pointMap.put(name, model);
		}
		return model;
	}
	
	ModelingPoint3D create(String name, CoordinateModel model){
		ModelingPoint3D child = new ModelingPoint3D(name);
		model.add(child.coordinateModel);
		child.parent = this;
		return child;
	}
}